<?php include_once("../../../common/common_setting_unit.php");         // 引入通用的设置文件 ?>
<?php include_once(ROOT_PATH_ . "/controller/common/module/head.php"); // 引入通用的头部 ?>
<?php include_once("../controller/data_list.php");                     // 当前页面的控制器 ?>



<body>

<!--顶部栏-->
<div id="topbar"> <?php include ROOT_PATH_ . '/controller/common/module/topbar.php'; ?></div>

<!--容器-->
<div id="container" class="<? echo $now_extender ?>">

    <!--侧边栏-->
    <div id="sidebar"><?php include ROOT_PATH_ . '/controller/common/module/sidebar.php'; ?></div>





    <?
    //==============================================================================
    //这里开始才是平常开发需要注重的部分，其余的基本不用理会
    //==============================================================================
    ?>

    <div id="content" class="layui-form">

			<?php $page_title='部门列表';?>
<fieldset class="layui-elem-field layui-field-title">
                <legend> <?php echo $page_title;?> </legend>
            </fieldset>

        
            <div class="list-box">
     			<a class="layui-btn white" href="detail-add.php?now_extender=department" type="submit">添加部门</a>
    			<div class="list-boxes">
    				<table class="layui-table" id="list-table">
      <colgroup>
     
        <col width="400">
        <col>
        <col>
        <col>
        <col>
        <col width="230">
      </colgroup>
      <thead>
        <tr> 

          <th>部门</th>
          <th>电话</th>
          <th>地址</th>
          <th>负责人</th>
          <th>备注</th>
          <th>操作</th>
        </tr> 
      </thead>
      <tbody>
    
        
        <?php  
        foreach($department_list as $val){
        ?>
        <tr id="item<?echo $val['nid']?>">
    
  
          <td>
              <?if(count($val[$val['name']]) > 0) {?>
            <img src="../asset/image/menu_plus.gif"
                 id="icon_<?echo $val['level']?>_<?echo $val['nid']?>"
                 width="9" height="9" border="0"
                 style="margin-left:<?echo $val['level']?>em"
                 data-state="plus"
                 onclick="rowClicked(this,<?echo $val['nid']?>)" />
            <?php }else{?>
            <img src="../asset/image/menu_arrow.gif" width="9" height="9" border="0"
                 style="margin-left:<?echo $val['level']?>em" />
            <?php }?>
            <?echo $val['name']?>
          </td>
          <td><?echo $val['phone']?></td>
         
          <td><?echo $val['location']?></td> 
          
          <td>
          	<?

				foreach($principal_list as $value){
					if($value['nid'] ==  $val['principal']){
						echo $value['name'];
					}
				}
			?>
          </td> 

           <td><?echo $val['remark']?></td>
         
          <td>
                  		<?php if($number == 0){?>
            <span
            onclick="deleter(<?php echo $val['nid'] ?>,'data_delete')"
            class="layui-btn layui-btn-sm layui-btn-primary">
            <i class="layui-icon">&#xe640;</i>删除
            </span>

    		<?php }?>
    
      <a class="layui-btn layui-btn-sm  " href="detail-edit.php?now_extender=<?echo $_REQUEST['now_extender'] ?>&nid=<? echo $val['nid']?>">
          <i class="layui-icon">&#xe642;</i> 编辑
      </a>
    


          </td>
        </tr>



<!--二级目录开始循环-->
            <?foreach ($val[$val['name']] as $val2) {?>
             <tr class="<?echo $val2['level']?>  children_of_<?echo $val['nid']?>" id="item<?echo $val2['nid']?>" style="display:none">

          <td >
                <?if(count($val2[$val2['name']]) > 0) {?>


            <img src="../asset/image/menu_minus.gif"
                 id="icon_<?echo $val2['level']?>_<?echo $val2['nid']?>"
                 width="9" height="9" border="0"
                 style="margin-left:1em"
                 data-state="minus"
<!--                 onclick="rowClicked(this,--><?//echo $val2['nid']?>//)"
            />
            <?php }else{?>
            <img src="../asset/image/menu_arrow.gif" width="9" height="9" border="0"
                 style="margin-left:1em" />
            <?php }?>

              <?echo $val2['name']?>
          </td>
          <td><?echo $val2['phone']?></td>

          <td><?echo $val2['location']?></td>

          <td>
          	<?

				foreach($principal_list as $value){
					if($value['nid'] ==  $val2['principal']){
						echo $value['name'];
					}
				}


			?>
          </td>

           <td><?echo $val2['remark']?></td>

          <td>


                  		<?php if($number == 0){?>

            <span
            onclick="deleter(<?php echo $val2['nid'] ?>,'data_delete')"
            class="layui-btn layui-btn-sm layui-btn-primary">
            <i class="layui-icon">&#xe640;</i>删除
            </span>

    		<?php }?>

      <a class="layui-btn layui-btn-sm  " href="detail-edit.php?now_extender=<?echo $_REQUEST['now_extender'] ?>&nid=<? echo $val2['nid']?>">
          <i class="layui-icon">&#xe642;</i> 编辑
      </a>



          </td>
        </tr>



<!-- 3级目录开始循环-->

                <?foreach ($val2[$val2['name']] as $val3) {?>

                    <tr class="<?echo $val2['level']?> grand_of_<?echo $val['nid']?>  children_of_<?echo $val2['nid']?>"  id="item<?echo $val2['nid']?>"  style="display:none">

                        <td  <?if(count($val3[$val3['name']]) < 1){?> style="padding-left:3em" <? ;}?> >
                            <?if(count($val3[$val3['name']]) > 0){?>
                            <?php if($val3['is_leaf'] != 1){?>
                                <img src="../asset/image/menu_minus.gif"
                                     id="icon_<?echo $val3['level']?>_<?echo $val3['nid']?>"
                                     width="9" height="9" border="0"
                                     style="margin-left:2em"
                                     data-state="minus"
                                     onclick="rowClicked(this)" />
                            <?php }else{?>
                                <img src="../asset/image/menu_arrow.gif" width="9" height="9" border="0"
                                     style="margin-left:2em" />
                            <?php }?>
                            <?}?>
                            <?echo $val3['name']?>
                        </td>
                        <td><?echo $val3['phone']?></td>

                        <td><?echo $val3['location']?></td>

                        <td>
                            <?

                                foreach($principal_list as $value){
                                    if($value['nid'] ==  $val3['principal']){
                                        echo $value['name'];
                                    }
                                }


                            ?>
                        </td>

                        <td><?echo $val3['remark']?></td>

                        <td>


                            <?php if($number == 0){?>

                                <span
                                        onclick="deleter(<?php echo $val3['nid'] ?>,'data_delete')"
                                        class="layui-btn layui-btn-sm layui-btn-primary">
            <i class="layui-icon">&#xe640;</i>删除
            </span>

                            <?php }?>

                            <a class="layui-btn layui-btn-sm  " href="detail-edit.php?now_extender=<?echo $_REQUEST['now_extender'] ?>&nid=<? echo $val3['nid']?>">
                                <i class="layui-icon">&#xe642;</i> 编辑
                            </a>



                        </td>
                    </tr>
                <?} ?>

        <?}?>


      <?php } ?>
    
    
    
    
      </tbody>
    </table>
   				</div>

    			
    		</div>

		</div>

</div>




<script>
    // Demo
    layui.use('form', function(){
        var form = layui.form;

        // 监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });

    var imgPlus = new Image();
    imgPlus.src = "../asset/image/menu_plus.gif";

    /**
     * 折叠分类列表
     */
    function rowClicked(obj,parent_nid) {


        parent_box="item"+parent_nid;

        //自己的子分类
        child_div = "children_of_"+parent_nid;

        //自己的孙分类
        grand_div = "grand_of_"+parent_nid;

        //这个是自己


        //为其子类和孙类添加加一个attr="show"


        //我的字类全部都反转显示。
        $("."+child_div).toggle();
        $("."+grand_div).toggle();





        // 当前图像
        img = obj;
        // 取得上二级tr>td>img对象
        obj = obj.parentNode.parentNode;
        // 整个分类列表表格
        var tbl = document.getElementById("list-table");
        // 当前分类级别
        var lvl = parseInt(obj.className);
        // 是否找到元素
        var fnd = false;
        var sub_display = img.src.indexOf('menu_minus.gif') > 0 ? 'none' : 'table-row';
        // 遍历所有的分类
        for (i = 0; i < tbl.rows.length; i++) {
            var row = tbl.rows[i];
            if (row == obj) {
                // 找到当前行
                fnd = true;
            } else {
                if (fnd == true) {
                    var cur = parseInt(row.className);
                    var icon = 'icon_' + row.id;
                    if (cur > lvl) {
                        row.style.display = sub_display;
                        if (sub_display != 'none') {
                            var iconimg = document.getElementById(icon);
                            if (iconimg) {
                                iconimg.src = iconimg.src.replace('../asset/image/menu_plus.gif', '../asset/image/menu_minus.gif');
                            }
                        }
                    } else {
                        fnd = false;
                        break;
                    }
                }
            }
        }

        for (i = 0; i < obj.cells[0].childNodes.length; i++) {
            var imgObj = obj.cells[0].childNodes[i];
            if (imgObj.tagName == "IMG") {
                if (imgObj.getAttribute('data-state') === 'plus') {
                    imgObj.src = '../asset/image/menu_minus.gif';
                    imgObj.setAttribute('data-state', 'minus');
                } else {
                    imgObj.src = '../asset/image/menu_plus.gif';
                    imgObj.setAttribute('data-state', 'plus');
                }
            }
        }
    }
</script>




<!--载入删除功能-->
<script type="text/javascript" src="/controller/common/asset/js/deleter.js"></script>

<?php include_once('../module/footer.php'); ?>
</body>
</html>
